<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/static/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/list.css" />
    <script type="text/javascript" src="/static/js/jquery-2.1.1.min.js"></script>
</head>

<body>
    <div class="header inner_c">
        <h1 class="fl"><a href="/" target="_blank" title="数据管理系统" alt="数据管理系统">数据管理系统</a></h1>
        <form action="" accept-charset="utf-8" class="search" id="dw__search" method="get"
            role="search">
            <div class="soso fl">
                <div class="kuang_w fl">
                    <input type="text" id="qsearch_in" accesskey="f" name="q" title="[F]" class="kuang"
                        placeholder="搜索本表">
                    <input type="text" style="display: none;">
                </div>
                <div class="sousuo_w fl">
                    <input type="button" class="sousuo" id="submit_ym">
                </div>
            </div>
        </form>
    </div>
    <div class="h10 cl"></div>

    <div class="wai">
        <div class="main">
            <!-- 目录 -->
            <div class="main_l fl" id="menu">

            </div>
            <div class="nei">
                <div class="main_m fl">
                    <div class="main_m_h" id="mbx">
                        <a href="/">首页</a>&nbsp;>&nbsp;<a href="/">元数据</a><span></span>
                    </div>
                    <div class="paixu" id="total">

                    </div>
                    <div id="liebiao_box">

                    </div>
                    <div class="fanye" id="fanye">

                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 底部的版权信息 -->
    <div class="footer">
        版权所有：国家材料环境腐蚀平台 京ICP备13025191号 京公网安备11010802015897号
    </div>
    <script type="text/javascript" src="/static/js/edataclass.js"></script>
    <script>
        // 获取url上的 classid & page & q
        var classid = 0;
        var q = '';
        var page = 0;
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == "classid") {
                classid = parseInt(pair[1]);
            }
            if (pair[0] == "q") {
                q = pair[1];
            }
            if (pair[0] == "page") {
                page = parseInt(pair[1]);
            }
        }
        // console.log(window.location.href);
        // 无classid 跳转首页
        // console.log(classid);
        if (classid == 0) {
            // return false;
            window.location.href = "/";
        }
        makemenu(classid);

        if (page <= 0) {
            page = 1;
        }

        if (q != '') {
            $("#qsearch_in").val(q);
        }
        var start_time = Date.now();
        $.ajax({
            type: "get",
            url: '/ajax/edata/getlist',
            data: {
                "classid": classid,
                "page": page,
                "q": q,
            },
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    console.log(data.data);
                    classInfo = data.data.classInfo;
                    var liebiao_str = "";
                    a_html = "detail.html";
                    if (classInfo.tablename=="photo") {
                        a_html = "photo.html";
                    }
                    data.data.list.forEach(elist => {
                        liebiao_str += '<div class="liebiao">';
                        liebiao_str += '<p class="lb_title"><a href="/'+a_html+'?classid=' +
                            classid + '&id=' + elist.id +
                            '" target="_blank" class="sys_url">' + elist.title + '</a></p>';
                        liebiao_str += '<div class="lb_content">';
                        liebiao_str += '<ul class="lb_ct_l fl">';
                        liebiao_str +=
                            '<li>材料名称:</li><li>材料类别:</li><li>老化周期(天):</li><li>数据来源:</li>	';
                        liebiao_str += '</ul>';
                        liebiao_str +=
                            '<a href="javascript:void(0)" class="lb_ct_m fl"><span>浏览量</span><b>00x</b></a>';
                        liebiao_str +=
                            '<div class="lb_ct_r fl"><a href="javascript:void(0)" class="shou">收藏</a> <a href="javascript:void(0)" target="_blank" class="yin">引用</a><a href="javascript:void(0)" target="_blank" class="xiang">相关文章</a><a href="javascript:void(0)" target="_blank" class="xia">下载</a>';
                        liebiao_str += '</div>';
                        liebiao_str += '</div>';
                        liebiao_str += '</div>';
                    });
                    $("#liebiao_box").append(liebiao_str);
                    var total = data.data.total;
                    if (q=='') {
                        $("#total").append('库内数据总量为&nbsp;<span>'+total+'</span>&nbsp;项');
                    } else {
                        var end_time = Date.now();
                        var use_time = (end_time - start_time) / 1000;
                        $("#total").append('大约有&nbsp;<span>'+total+'</span>&nbsp;项符合查询结果。（搜索耗时: <span>'+use_time+'</span>秒）');
                    }

                    var fanye_str = "";
                    var pages = Math.ceil(total / 15);

                    fanye_str += '页次：' + page + '/' + pages + '&nbsp;每页15&nbsp;总数' + total + '&nbsp;&nbsp;&nbsp;&nbsp;';
                    if (page == 1) {
                        fanye_str += '首页&nbsp;&nbsp;上一页&nbsp;&nbsp;';
                    } else {
                        fanye_str += '<a href="/datalist.html?classid=' + classid +'&page=1&q='+q+'">首页</a>&nbsp;&nbsp;';
                        fanye_str += '<a href="/datalist.html?classid=' + classid + '&page=' + (page - 1) + '&q='+q+'">上一页</a>&nbsp;&nbsp;';
                    }
                    if (page >= pages) {
                        fanye_str += '下一页&nbsp;&nbsp;尾页&nbsp;&nbsp;';
                    } else {
                        fanye_str += '<a href="/datalist.html?classid=' + classid + '&page=' + (page + 1) + '&q='+q+'" >下一页</a>&nbsp;&nbsp;';
                        fanye_str += '<a href="/datalist.html?classid=' + classid + '&page=' + pages + '&q='+q+'">尾页</a>&nbsp;&nbsp;';
                    }
                    fanye_str += '转到:<input type="number" name="gotopage" min="0" max="' + pages +
                        '" data-max="' + pages + '" value="' + page + '" id="gotopage" />';
                    fanye_str += '<button name="Go"  onclick="goto()">Go</button>';
                    $("#fanye").append(fanye_str);
                }
            }
        });
        // datalist.html?q=广州&baseclass_id=174&classid=179&table_id=478
        // 分页跳转到指定页面
        function goto() {
            var gopage = $("#gotopage").val();
            var maxpage = $("#gotopage").data('max');
            if (gopage > maxpage) {
                alert("当前搜索最多只有" + maxpage + "页, 请输入小于此数的页码");
                return false;
            }
            self.location.href = '/datalist.html?classid=' + classid + '&page=' + gopage + '&q='+q;
        }

        // 搜索按钮
        $("#submit_ym").on("click", function(){
            gosubmit()
        });

        // input框绑定回车键
	    $('#qsearch_in').bind('keydown',function(event){
            if(event.keyCode == "13")
            {
                gosubmit()
            }
        });

        // 执行跳转
        function gosubmit() {
            var newq = $("#qsearch_in").val();
            self.location.href = '/datalist.html?classid=' + classid + '&page=' + page + '&q='+newq;
        }
    </script>

</body>

</html>